package com.example.dao;

import com.example.domain.AddressBook;
import jakarta.servlet.http.PushBuilder;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookDao {
    @Select("select * from address_book where user_id=#{userId} limit #{pageCount},#{pageSize}")
    public List<AddressBook> selectall(int pageCount,int pageSize,Long userId);

    @Select("select count(*) from address_book where id=#{userId}")
    public int getcount(Long userId);

    @Select("select * from address_book where user_id=#{userId}")
    public List<AddressBook> list(Long userId);

    @Update("update address_book set is_default=0 where user_id=#{userId}")
    public void setstatusall(Long userId);

    @Update("update address_book set is_default=1,update_time=#{updateTime},update_user=#{updateUser} where id=#{id}")
    public void setstatusone(AddressBook addressBook);

    @Insert("insert into address_book (id,user_id,consignee,sex,phone,detail,label,is_default,create_time,update_time,create_user,update_user,is_deleted) values (#{id},#{userId},#{consignee},#{sex},#{phone},#{detail},#{label},#{isDefault},#{createTime},#{updateTime},#{createUser},#{updateUser},#{isDeleted})")
    public void save(AddressBook addressBook);

    @Select("select * from address_book where id=#{id}")
    public AddressBook alert(Long id);

    @Update("update address_book set consignee=#{consignee},sex=#{sex},phone=#{phone},detail=#{detail},label=#{label},update_time=#{updateTime},update_user=#{updateUser} where id=#{id}")
    public void update(AddressBook addressBook);

    @Delete("delete from address_book where id=#{id}")
    public void delete(Long id);

    @Select("select * from address_book where user_id=#{userId} and is_default=1")
    public AddressBook getdefault(Long userId);

    @Select("select * from address_book where user_id=#{userId} and is_default=1")
    public AddressBook selectbydefault(Long userId);
}
